package com.huajin.gateway.util;

import com.huajin.gateway.netcard.domain.NetCard;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
    private static Pattern r;
    // 现在创建 matcher 对象
    private static Matcher m;


    public static String getRegexResult1(String pattern, String content) {

        // 创建 Pattern 对象
        r = Pattern.compile(pattern);
        // 现在创建 matcher 对象
        m = r.matcher(content);
        if (m.find()) {
            System.out.println("Found value: " + m.group(0));
            return m.group(0).split(" ")[1];
        }
        return null;
    }

    public static boolean getRegexResult2(String pattern, String content) {

        // 创建 Pattern 对象
        r = Pattern.compile(pattern);
        // 现在创建 matcher 对象
        m = r.matcher(content);
        if (m.find()) {
            System.out.println("Found value: " + m.group(0));
            return true;
        }
        return false;
    }

    public static List<String> getRegexResultCardName(String pattern, String content) {
        List<String> results = new ArrayList<>();
        // 创建 Pattern 对象
        r = Pattern.compile(pattern);
        // 现在创建 matcher 对象
        m = r.matcher(content);
        while (m.find()) {
            System.out.println("Found value: " + m.group(1));
            results.add(m.group(1));
        }
        return results;
    }
}
